var util = require('util');
var _ = require('lodash');
_.defaults = require('merge-defaults');
var fs = require('fs');
var path = require('path');
_.str = require('underscore.string');

var coffee = require('coffee-script');


module.exports = function (fileName) {

  var _readCoffee = function (modelFile) {
    // 读取model文件
    var modelPath = path.resolve(__dirname, '../api/models/' + modelFile);
    var model = fs.readFileSync(modelPath, 'utf8');

    return coffee.eval(model);
  };

  var evalModel = _readCoffee(fileName);
  var attributes = evalModel.attributes;
  var _page = evalModel.page;

  var _attMap = {};

  for (var key in attributes) {
    var val = attributes[key];
    if(val.page) {
      _attMap[key] = val;
    }
  }

  return {
    page: _page,
    attributes: _attMap
  };


}

